<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="销售订单编号" prop="soNumber">
        <el-input
          v-model="queryParams.soNumber"
          placeholder="请输入销售订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品物料编码" prop="itemCode">
        <el-input
          v-model="queryParams.itemCode"
          placeholder="请输入产品物料编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产品物料名称" prop="itemName">
        <el-input
          v-model="queryParams.itemName"
          placeholder="请输入产品物料名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="单位" prop="unitOfMeasure">
        <el-input
          v-model="queryParams.unitOfMeasure"
          placeholder="请输入单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="单价" prop="unitPrice">
        <el-input
          v-model="queryParams.unitPrice"
          placeholder="请输入单价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="数量" prop="quantity">
        <el-input
          v-model="queryParams.quantity"
          placeholder="请输入数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="总金额" prop="totalAmount">
        <el-input
          v-model="queryParams.totalAmount"
          placeholder="请输入总金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="发货数量" prop="shipped">
        <el-input
          v-model="queryParams.shipped"
          placeholder="请输入发货数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="发货金额" prop="shippedPrice">
        <el-input
          v-model="queryParams.shippedPrice"
          placeholder="请输入发货金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="出库数量" prop="issue">
        <el-input
          v-model="queryParams.issue"
          placeholder="请输入出库数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="出库金额" prop="issuePrice">
        <el-input
          v-model="queryParams.issuePrice"
          placeholder="请输入出库金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="退货数量" prop="salesReturn">
        <el-input
          v-model="queryParams.salesReturn"
          placeholder="请输入退货数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="退货金额" prop="salesReturnPrice">
        <el-input
          v-model="queryParams.salesReturnPrice"
          placeholder="请输入退货金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="已完工入库数量" prop="finished">
        <el-input
          v-model="queryParams.finished"
          placeholder="请输入已完工入库数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
<!--      <el-form-item label="已完工入库金额" prop="finishedPrice">
        <el-input
          v-model="queryParams.finishedPrice"
          placeholder="请输入已完工入库金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
<!--      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['xs:condition:add']"
        >新增</el-button>
      </el-col>-->
<!--      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['xs:condition:edit']"
        >修改</el-button>
      </el-col>-->
<!--      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['xs:condition:remove']"
        >删除</el-button>
      </el-col>-->
<!--      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['xs:condition:export']"
        >导出</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <div class="table-container"  style="max-height: 600px; overflow: auto;">
      <el-table
        v-loading="loading"
        :data="conditionList"
        border
        stripe
        highlight-current-row
        style="width: 100%;min-width: 1800px; white-space: nowrap;"
        @selection-change="handleSelectionChange">
        <!--      <el-table-column type="selection" width="55" align="center" />
              <el-table-column label="ID" align="center" prop="id" />-->
        <el-table-column label="销售订单编号" align="center" prop="soNumber" width="150">
          <template slot-scope="scope">
            <span style="white-space: nowrap;display: inline-block;">{{ scope.row.soNumber }}</span>
          </template>
        </el-table-column>
        <el-table-column label="产品物料编码" align="center" prop="itemCode" width="140">
          <template slot-scope="scope">
            <span style="white-space: nowrap;display: inline-block;">{{ scope.row.itemCode }}</span>
          </template>
        </el-table-column>
        <el-table-column label="产品物料名称" align="center" prop="itemName" width="200">
          <template slot-scope="scope">
            <span style="white-space: nowrap;display: inline-block;">{{ scope.row.itemName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="单位" align="center" prop="unitOfMeasure"  width="auto"/>
        <el-table-column label="单价" align="center" prop="unitPrice"  width="auto"/>
        <el-table-column label="数量" align="center" prop="quantity"  width="auto"/>
        <el-table-column label="总金额" align="center" prop="totalAmount"  width="auto"/>
        <el-table-column label="发货数量" align="center" prop="shipped"  width="auto"/>
        <el-table-column label="发货金额" align="center" prop="shippedPrice"  width="auto"/>
        <el-table-column label="出库数量" align="center" prop="issue"  width="auto"/>
        <el-table-column label="出库金额" align="center" prop="issuePrice"  width="auto"/>
        <el-table-column label="退货数量" align="center" prop="salesReturn"  width="auto"/>
        <el-table-column label="退货金额" align="center" prop="salesReturnPrice"  width="auto"/>
        <el-table-column label="完工入库数量" align="center" prop="finished"  width="auto"/>
        <el-table-column label="完工入库金额" align="center" prop="finishedPrice"  width="auto"/>
        <!--      <el-table-column label="备注" align="center" prop="remark" />-->
        <!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-edit"
                    @click="handleUpdate(scope.row)"
                    v-hasPermi="['xs:condition:edit']"
                  >修改</el-button>
                  <el-button
                    size="mini"
                    type="text"
                    icon="el-icon-delete"
                    @click="handleDelete(scope.row)"
                    v-hasPermi="['xs:condition:remove']"
                  >删除</el-button>
                </template>
              </el-table-column>-->
      </el-table>
    </div>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改销售订单执行情况对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="销售订单编号" prop="soNumber">
          <el-input v-model="form.soNumber" placeholder="请输入销售订单编号" />
        </el-form-item>
        <el-form-item label="产品物料编码" prop="itemCode">
          <el-input v-model="form.itemCode" placeholder="请输入产品物料编码" />
        </el-form-item>
        <el-form-item label="产品物料名称" prop="itemName">
          <el-input v-model="form.itemName" placeholder="请输入产品物料名称" />
        </el-form-item>
        <el-form-item label="单位" prop="unitOfMeasure">
          <el-input v-model="form.unitOfMeasure" placeholder="请输入单位" />
        </el-form-item>
        <el-form-item label="单价" prop="unitPrice">
          <el-input v-model="form.unitPrice" placeholder="请输入单价" />
        </el-form-item>
        <el-form-item label="数量" prop="quantity">
          <el-input v-model="form.quantity" placeholder="请输入数量" />
        </el-form-item>
        <el-form-item label="总金额" prop="totalAmount">
          <el-input v-model="form.totalAmount" placeholder="请输入总金额" />
        </el-form-item>
        <el-form-item label="发货数量" prop="shipped">
          <el-input v-model="form.shipped" placeholder="请输入发货数量" />
        </el-form-item>
        <el-form-item label="发货金额" prop="shippedPrice">
          <el-input v-model="form.shippedPrice" placeholder="请输入发货金额" />
        </el-form-item>
        <el-form-item label="出库数量" prop="issue">
          <el-input v-model="form.issue" placeholder="请输入出库数量" />
        </el-form-item>
        <el-form-item label="出库金额" prop="issuePrice">
          <el-input v-model="form.issuePrice" placeholder="请输入出库金额" />
        </el-form-item>
        <el-form-item label="退货数量" prop="salesReturn">
          <el-input v-model="form.salesReturn" placeholder="请输入退货数量" />
        </el-form-item>
        <el-form-item label="退货金额" prop="salesReturnPrice">
          <el-input v-model="form.salesReturnPrice" placeholder="请输入退货金额" />
        </el-form-item>
        <el-form-item label="已完工入库数量" prop="finished">
          <el-input v-model="form.finished" placeholder="请输入已完工入库数量" />
        </el-form-item>
        <el-form-item label="已完工入库金额" prop="finishedPrice">
          <el-input v-model="form.finishedPrice" placeholder="请输入已完工入库金额" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCondition, getCondition, delCondition, addCondition, updateCondition } from "@/api/mes/xs/condition";

export default {
  name: "Condition",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 销售订单执行情况表格数据
      conditionList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        soNumber: null,
        itemCode: null,
        itemName: null,
        unitOfMeasure: null,
        unitPrice: null,
        quantity: null,
        totalAmount: null,
        shipped: null,
        shippedPrice: null,
        issue: null,
        issuePrice: null,
        salesReturn: null,
        salesReturnPrice: null,
        finished: null,
        finishedPrice: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询销售订单执行情况列表 */
    getList() {
      this.loading = true;
      listCondition(this.queryParams).then(response => {
        this.conditionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        soNumber: null,
        itemCode: null,
        itemName: null,
        unitOfMeasure: null,
        unitPrice: null,
        quantity: null,
        totalAmount: null,
        shipped: null,
        shippedPrice: null,
        issue: null,
        issuePrice: null,
        salesReturn: null,
        salesReturnPrice: null,
        finished: null,
        finishedPrice: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加销售订单执行情况";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCondition(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改销售订单执行情况";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCondition(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCondition(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除销售订单执行情况编号为"' + ids + '"的数据项？').then(function() {
        return delCondition(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('xs/condition/export', {
        ...this.queryParams
      }, `condition_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style scoped>.table-container {
  max-height: 600px;
  overflow: auto;
}
::v-deep .el-table__cell {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
